<template>
	<view class="data-item">
		<view class="order-type">
			<view>设备维修: <text>{{value.apply_no}}</text></view>
			<!-- <view class="type red">待接单</view> -->
			<!-- <view class="type blue">已报修</view>
			<view class="type yellow">巡查异常</view> -->
		</view>
		<view class="order-info">
			<view class="info-item">
				<view class="key">设备信息：</view>
				<text style="word-break:break-all;">{{value.pd_device_repair.device_code}}-{{value.pd_device_repair.device_name}}</text>
			</view>
			<view class="info-item"><view class="key">故障描述：</view>{{value.pd_device_repair.repair_content}}</view>
			<view class="info-item"><view class="key">设备地址：</view>{{value.pd_device_repair.address || '-'}}</view>
			<view v-if="value.pd_device_repair.apply_image" class="info-item"><view class="key">现场图片：</view>
				<image-list :pics="value.pd_device_repair.apply_image"></image-list>
			</view>
		</view>
		<view v-if="(value.pd_device_repair.status === '10' ) && $util.getRights().pd_device_repair_apply" class="handle-btn">
			<view @click="cancleTask">取消申请</view>
			<view @click="subimtApply">提交申请</view>
		</view>
		<!-- <view v-else-if="value.pd_device_repair.status === '20' && $util.getRights().pd_device_repair_apply" class="handle-btn">
			<view @click="cancleTask">取消申请</view>
		</view> -->
		<view v-else-if="value.pd_device_repair.status === '20' && $util.getRights().pd_device_repair_dispatch" class="handle-btn">
			<view @click="cancleTask" v-if="userId == value.pd_device_repair.apply_user_id">取消申请</view>
			<view @click="acceptTask">派单</view>
		</view>
		<view v-else-if="value.pd_device_repair.status === '20' && $util.getRights().pd_device_repair_taking" class="handle-btn">
			<view @click="cancleTask" v-if="userId == value.pd_device_repair.apply_user_id">取消申请</view>
			<view @click="acceptTask">立即接单</view>
		</view>
		<view v-else-if="value.pd_device_repair.status === '30'" class="handle-btn">
			<view @click="rollbackTaking" v-if="$util.getRights().pd_device_repair_register || $util.getRights().pd_device_repair_dispatch">退回接单</view>
			<view @click="done" v-if="$util.getRights().pd_device_repair_register">立即处理</view>
			<view v-else @click="viewDetail">查看详情</view>
		</view>
		<view v-else-if="value.pd_device_repair.status === '40'" class="handle-btn">
			<view @click="confirm" v-if="$util.getRights().pd_device_repair_assess">评价</view>
			<view v-else @click="viewDetail">查看详情</view>
		</view>
		<!-- <view v-else-if="value.pd_device_repair.status === '40'" class="handle-btn">
			<view @click="check" v-if="$util.getRights().pd_device_repair_check">抽查</view>
			<view v-else @click="viewDetail">查看详情</view>
		</view> -->
		<!-- <view v-else-if="value.pd_device_repair.status === '90'" class="handle-btn">
			<view @click="done" v-if="$util.getRights().pd_device_repair_register">立即处理</view>
			<view v-else @click="viewDetail">查看详情</view>
		</view> -->
		<view v-else class="handle-btn">
			<view @click="viewDetail">查看详情</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'DeviceRepair',
	props:{
		value: {
			type: Object,
			default: ()=>{
				return {
					userId: '',
				}
			}
		}
	},
	data(){
		return {
		}
	},
	created(){
		let loginInfo = this.$util.getStorage("loginInfo")
		this.userId = loginInfo.id
		console.log('222555236545',this.$util.getRights())
	},
	methods:{
		subimtApply(item){
			uni.navigateTo({
				url: '/pagesA/facility-fix/facility-fix-create?repairId=' + this.value.pd_device_repair.repair_id
			})
		},
		viewDetail(item){
			console.warn("item: ", item)
			uni.navigateTo({
				url: '/pagesA/facility-fix/facility-fix-detail?repairId=' + this.value.pd_device_repair.repair_id
			})
		},
		cancleTask(){
			uni.navigateTo({
				url: '/pagesA/facility-fix/facility-fix-cancel?repairId=' + this.value.pd_device_repair.repair_id
			})
		},
		acceptTask(){
			uni.navigateTo({
				url: '/pagesA/facility-fix/facility-fix-accept?repairId=' + this.value.pd_device_repair.repair_id
			})
		},
		done() {
			uni.navigateTo({
				url: '/pagesA/facility-fix/facility-fix-done?repairId=' + this.value.pd_device_repair.repair_id //isInList=true&data='+JSON.stringify(this.value)
			})
		},
		confirm() {
			uni.navigateTo({
				url: '/pagesA/facility-fix/facility-fix-evaluate?repairId=' + this.value.pd_device_repair.repair_id //isInList=true&data='+JSON.stringify(this.value)
			})
		},
		rollbackTaking() {
			this.$util.confirm({
				content: "确定要退回当前接单？",
				confirmText: "退回"
			}).then(isConfirm => {
				if (isConfirm) {
					this.$util.post({
						url: "app/pdDeviceRepair/rollbackTaking",
						data: {
							repair_id: this.value.pd_device_repair.repair_id
						}
					}).then(res => {
						// console.log('22=========refreshPatrolTask')
						uni.$emit('refreshDeviceRepair')
						uni.$emit('refreshHomeDataList')
					})
				}
			})
		},
	}
}
</script>

<style lang="scss" scoped>
@import './style.scss';

.type{
	font-size: 24rpx;
	font-weight: bolder;
	padding: 12rpx;
	border-radius: 4rpx;
}
.red{
	color: #FF3737;
	background-color: #FFEFEF;
}
.yellow{
	color: #FF972C;
	background-color: #FFF8EF;
}
.blue{
	color: #2C72FF;
	background-color: rgba($color: #A5C2FF, $alpha: .16);
}
</style>
